package com.lh.tams.dao.system;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.lh.tams.controller.qo.MinLawQo;
import com.lh.tams.dao.base.HibernateBaseDao;
import com.lh.tams.domain.TamsMinLaw;
import com.lh.tams.util.DataGridModel;
import com.lh.tams.util.Page;

/**
 * 法律法规小类管理DAO
 * @author liulin
 * @version 2012-06-20
 */
@Repository
public class LawMinDao extends HibernateBaseDao{
	
	/**
	 * 分页查询
	 * @param dgm
	 * @param tamsMinLaw
	 * @return
	 */
	public Page query(DataGridModel dgm,MinLawQo minLawQo){
		List<Object> args=new ArrayList<Object>();
		StringBuilder hql=new StringBuilder();
		hql.append("from TamsMinLaw tn where 1=1");
		if(minLawQo.getLawMinName()!=null&&!"".equals(minLawQo.getLawMinName())){
			hql.append(" and tn.lawMinName like ?");
			args.add("%"+minLawQo.getLawMinName()+"%");
		}
		if(minLawQo.getMaxId()>0){
			hql.append(" and tn.tamsMaxLaw.idBgt=?");
			args.add(minLawQo.getMaxId());
		}
		return super.queryForList(hql.toString(), args.toArray(), dgm.getPage(), dgm.getRows());
	}
	
	/**
	 * 批量删除
	 * @param ids
	 */
	public void delete(long[] ids){
		super.delete("TAMS_MIN_LAW", ids);
	}
	
	/**
	 * 根据大类查询所有小类
	 * @param id
	 * @return
	 */
	public List<TamsMinLaw> queryPersonIdByMax(long id){
		String hql="from TamsMinLaw t where t.tamsMaxLaw.idBgt=?";
		List<TamsMinLaw> list= getHibernateTemplate().find(hql, new Object[]{id});
		return list;
	}
}
